package router

import (
	"net/http"
)

type route struct {
	Uri       string
	Method    string
	CallBack  func(http.ResponseWriter, *http.Request)
	RunnerNum int64
	Runners   []chan interface{}
}

type Writer = http.ResponseWriter

type Request = *http.Request

type RouteList struct {
	TotalRunner int64
	List        []*route
}

var _routeList RouteList

func Get(uri string, callback func(Writer, Request)) {
	_routeList.List = append(_routeList.List, &route{
		Uri:       uri,
		Method:    "GET",
		CallBack:  callback,
		RunnerNum: 0,
	})
}

func Post(uri string, callback func(Writer, Request)) {
	_routeList.List = append(_routeList.List, &route{
		Uri:       uri,
		Method:    "POST",
		CallBack:  callback,
		RunnerNum: 0,
	})
}

func Put(uri string, callback func(Writer, Request)) {
	_routeList.List = append(_routeList.List, &route{
		Uri:       uri,
		Method:    "PUT",
		CallBack:  callback,
		RunnerNum: 0,
	})
}

func Delete(uri string, callback func(Writer, Request)) {
	_routeList.List = append(_routeList.List, &route{
		Uri:       uri,
		Method:    "DELETE",
		CallBack:  callback,
		RunnerNum: 0,
	})
}

func Options(uri string, callback func(Writer, Request)) {
	_routeList.List = append(_routeList.List, &route{
		Uri:       uri,
		Method:    "OPTIONS",
		CallBack:  callback,
		RunnerNum: 0,
	})
}

func GetRoute() RouteList {
	return _routeList
}
